package com.dataextend.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;

@Slf4j
@Configuration
public class ClickhouseConfig {
    @Value("${spring.second-datasource.clickDriverClassName}")
    private String driver;
    @Value("${spring.second-datasource.clickurl}")
    private String url;
    @Value("${spring.second-datasource.clickusername}")
    private String username;
    @Value("${spring.second-datasource.clickpassword}")
    private String password;

    @Value("${spring.second-datasource.clickinitialSize}")
    private String initialSize;
    @Value("${spring.second-datasource.clickmaxActive}")
    private String maxActive;
    @Value("${spring.second-datasource.clickminIdle}")
    private String minIdle;
    @Value("${spring.second-datasource.clickmaxWait}")
    private String maxWait;


    @Bean
    public DataSource dataSource(){
        log.info("----->clickhouseDriver:" + driver + " url:" + url);
        DruidDataSource datasource = new DruidDataSource();

        datasource.setUrl(url);
        datasource.setDriverClassName(driver);
        datasource.setUsername(username);
        datasource.setPassword(password );
        datasource.setInitialSize(Integer.parseInt(initialSize));
        datasource.setMinIdle(Integer.parseInt(minIdle));
        datasource.setMaxActive(Integer.parseInt(maxActive));
        datasource.setMaxWait(Long.parseLong(maxWait));

        return datasource;
    }



}
